package ustc.xiaoyang.lingchashan.doublepointer;

import java.util.Collections;
import java.util.List;

/**
 * 2824.统计和小于目标的下标对数目 easy
 */
public class CountPairs2824 {
    public int countPairs(List<Integer> nums,int target){
        int ans = 0;
        Collections.sort(nums);
        int l = 0;
        int r = nums.size()-1;
        while(l<r){
            int sum = nums.get(l) + nums.get(r);
            if(sum < target){
                ans += r - l;
                l++;
            }else{
                r--;
            }
        }
        return ans;
    }
}
